﻿using System;
using System.Text;
using System.Data;

using DreamCube.Framework.DataAccess.Basic;
using DreamCube.Framework.DataAccess.Sqlserver;
using DreamCube.Foundation.Basic.Utility;

namespace DreamCube.Websites.UI.Projects.Films.Pages
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                MakeRecommend();
            }
        }

        protected void Make()
        { }

        /// <summary>
        /// 生成推荐电影
        /// </summary>
        protected void MakeRecommend()
        {
            try
            {
                String sql = "SELECT TOP 27 * FROM Video ORDER BY scores";
                Database db = DBManager.GetDBByConnectionString(BLL.WebSession.CurrentSystem.ConnectionStrings[0]);
                DataTable data = db.ExecuteTable(sql);
                if (data == null || data.Rows.Count <= 0) return;
                StringBuilder sb = new StringBuilder();
                for (Int32 i = 0; i < data.Rows.Count; i++)
                {
                    DataRow row = data.Rows[i];
                    i++;
                    switch (i)
                    {
                        case 1:
                        case 2:
                        case 3:
                            sb.AppendFormat("<li><a title=\"{0}\" href=\"Film_{1}.aspx\">", row["FilmName"].ToString(), row["id"].ToString());
                            sb.AppendFormat("<img class=\"KS_Pic\" height=\"125\" width=\"105\"  border=\"0\" src=\"Upload/{0}\" onerror=\"this.src='images/nopic.gif'\" /></a><br/>\n", row["FilmPic"].ToString());
                            sb.AppendFormat("<a title=\"{0}\" href=\"Film_{1}.aspx\">{2}</a></li>\n", row["FilmName"].ToString(), row["id"].ToString(), MyString.Cut(row["FilmName"].ToString(), 7));
                            break;
                        case 4:
                            LtTop1.Text = sb.ToString();
                            sb = new StringBuilder();
                            sb.AppendFormat("<li><a title=\"{0}\" href=\"Film_{1}.aspx\">{2}</a></li>\n", row["FilmName"].ToString(), row["id"].ToString(), MyString.Cut(row["FilmName"].ToString(), 9));
                            break;
                        default:
                            sb.AppendFormat("<li><a title=\"{0}\" href=\"Film_{1}.aspx\">{2}</a></li>\n", row["FilmName"].ToString(), row["id"].ToString(), MyString.Cut(row["FilmName"].ToString(), 9));
                            break;
                    }
                }
                ltTop2.Text = sb.ToString();
            }
            catch (Exception ex)
            {
                MyLog.MakeLog(ex);
            }
        }
    }
}